#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 100010;
using ll = long long;
int n, m;
ll f[N], s[N], q[N];
ll g(int i)
{
    if (!i) return 0;
    return f[i - 1] - s[i];
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> s[i], s[i] += s[i - 1];
    int hh = 0, tt = -1;
    for (int i = 0; i <= n; i++)
    {
        if (hh <= tt && q[hh] < i - m) hh++;
        if (i)f[i] = max(f[i - 1], g(q[hh]) + s[i]);
        while (hh <= tt && g(q[tt]) <= g(i)) tt--;
        q[++tt] = i;

    }
    cout << f[n] << endl;
}